Release 10.1A: OpenEdge Development:
Progress 4GL Reference
CLASS statement
Defines a user-defined class, as well as the data members and methods that comprise the class.
Note: This statement is applicable only when used in a class definition (.cls) file.Syntax
type-nameA character string that specifies the type name of the class. Specify a class type name using the
package.class-namesyntax as described in the Type-name syntax reference entry in this book.INHERITSsuper-type-nameAn optional character string that specifies the type name of a super class whose state and behavioral characteristics the new class inherits. The new class becomes a subclass of this super class. Specify a super class type name using the
package.class-namesyntax as described in the Type-name syntax reference entry in this book.The class definition (
.cls) file for the super class must be found at compile time.IMPLEMENTSinterface-type-name[,interface-type-name] ...An optional character string that specifies the type name of one or more interfaces the new class implements. The new class must implement all methods defined in the specified interfaces. Specify an interface type name using the
package.class-namesyntax as described in the Type-name syntax reference entry in this book.The class definition (
.cls) file for the interface must be found at compile time.For more information about defining an interface, see the INTERFACE statement reference entry in this book.
USE-WIDGET-POOLDirects Progress to create an unnamed widget pool scoped to this class. When specified, all dynamic object instances are created in the unnamed widget-pool by default. Otherwise, object instances are created in the session unnamed widget-pool. Progress deletes the unnamed widget-pool when the object instance is deleted.
You can also define a named or unnamed widget-pool in a class definition file. If you define a named widget-pool, object instances are created in that widget-pool only if you explicitly reference the widget-pool name.
When you define an unnamed widget-pool in a method, it is scoped to that method. You can delete the widget-pool within the method by using the DELETE WIDGET-POOL statement, or let Progress delete the widget-pool when the method ends.
For more information about defining and using widget-pools within a class, see OpenEdge Getting Started: Object-oriented Programming .
FINALIndicates the class cannot be inherited by another class. That is, it cannot be used in the INHERITS phrase in another class definition. Define a class as FINAL when you do not want any of its state or behavior overridden.
class-bodyThe body of a class definition is composed of the following types of elements:
Example
- Data members, which define the instance data or state of the class.
- Constructor method, which is invoked when the object is instantiated.
- Methods, which define the behavior of the class.
- Destructor method, which is invoked when the object is deleted.
You can define data members, class-specific methods, and the constructor and destructor methods in any order.
You can also specify ON statements within the body of a class definition.
Define elements in the class body using the following syntax:
data-member-definitionsDefines one or more data members in the class. Table 12 lists the types of data members you can define and their associated Progress 4GL DEFINE statement.
Table 12: Class data member types Data member type Progress 4GL DEFINE statement BROWSE widget BUFFER object BUTTON widget CLASS object DEFINE VARIABLE statement with the AS CLASS option (defines a variable as an object reference for a class or an interface) DATASET object DATA-SOURCE object FRAME widget HANDLE IMAGE widget MENU widget QUERY object RECTANGLE widget STREAM SUB-MENU widget TEMP-TABLE object VARIABLE DEFINE VARIABLE statement (defines a variable as a data member for a class) WIDGET-HANDLE WORK-TABLE widgetFor more information about these data member types, and any class-related restrictions, see the associated Progress 4GL DEFINE statement reference entry in this book.
constructor-definitionDefines a constructor method for the class using the CONSTRUCTOR statement. Progress invokes this constructor method to initialize data or state for a new class object instance when the object is instantiated using the NEW statement. You can define only one constructor method for a class. You cannot invoke a constructor method directly. If not defined, Progress provides a default constructor method that takes no parameters. For more information, see the CONSTRUCTOR statement reference entry in this book.
method-definitionsDefines one or more methods in the class. For more information, see the METHOD statement reference entry in this book.
destructor-definitionDefines a destructor method for the class using the DESTRUCTOR statement. Progress invokes this destructor method when the object is deleted using the DELETE OBJECT statement. You cannot invoke a destructor method directly. If not defined, Progress provides a default destructor method. For more information, see the DESTRUCTOR statement reference entry in this book.
END [ CLASS ]Specifies the end of the class body definition. You must end the class body definition with the END statement.
The following example shows the definition of a class that inherits a super class and defines several data members:
Notes
- You can terminate a CLASS statement with either a period (.) or a colon (:).
- A complete class definition must begin with the CLASS statement and end with the END statement.
- The access mode for a class definition is always PUBLIC.
- A class definition (
.cls) file can contain only one class definition.- In effect, a user-defined class represents a unique data type. In Progress, you can use a class just as you would any Progress built-in data type. You can define variables, parameters and return types as a class. You can also assign an object reference for a class object instance to a temporary table field defined as a Progress.Lang.Object; but you cannot assign an object reference to a field in a database table.
- You can reference include files from within a class definition file. For more information about include files, see the { } Include file reference entry in this book.
- All built-in preprocessor directives are supported in class definition files.
- All built-in preprocessor names are supported in class definition files. For a list of preprocessor name, see the { } Preprocessor name reference entry in this book.
- You cannot pass compile-time arguments to class definition files. However, you can pass compile-time arguments to include files referenced in a class definition file.
- The compiled version of a class definition file is an r-code (
.r) file. For more information, see the COMPILE statement reference entry in this book.- You cannot run r-code compiled for a class definition file with the RUN statement.
- You cannot define a data member, of any data type, in a subclass using the same name as a PUBLIC or PROTECTED data member in one of its super classes.
- PUBLIC and PROTECTED variables defined as data members within a class definition (.
cls) file maintain their characteristic throughout the inherited class hierarchy. Do not repeat variable definitions in any inherited class definition files.- You create an object instance of a class, and assign an object reference to the instance, using the NEW statement. You access a class object instance, as well as its data members and methods, using its associated object reference. For more information about the NEW statement, see the NEW statement reference entry in this book.
- Progress provides a system reference for the currently running object instance of this class, called THIS-OBJECT. For more information, see the THIS-OBJECT system reference entry in this book.
- If this class is a subclass of some super class, you can use the SUPER system reference to access the PUBLIC and PROTECTED methods of all super classes within the inherited class hierarchy. For more information, see the SUPER system reference entry in this book.
- You can store class definition r-code files in Progress procedure libraries. If Progress encounters a procedure library on
PROPATH, it will search the library for the specified r-code. However, you cannot execute r-code files stored in a procedure library that is not onPROPATHusing theprocedure-library-path<<member-name>> syntax.- You cannot define a NEW SHARED or NEW GLOBAL SHARED variable in a class definition (.
cls) file.- You cannot use ActiveX controls within a class definition (.
cls) file.- You can use COM automation objects within a class definition (.
cls) file. However, any event handlers for the object must be defined in a procedure file.- You cannot define an array of classes.
- For more information about class definition (
.cls) files, see OpenEdge Getting Started: Object-oriented Programming .See also
CONSTRUCTOR statement, DEFINE PARAMETER statement, DEFINE VARIABLE statement, DESTRUCTOR statement, INTERFACE statement, METHOD statement, NEW statement
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |